// 导入StoreOptions类型
import { StoreOptions } from "vuex";
import ACCESS_ENUM from "@/access/accessEnum";
import {UserControllerService} from "../../generated" 
// 定义默认导出的对象
export default {
  // 开启命名空间
  namespaced: true,
  // 初始状态
  state: () => ({
    loginUser: {
      userName: "未登录",
    },
  }),
  // 动作
  actions: {
    // 从远程获取用户登录信息
    async getLoginUser({ commit, state }, payload) {
      const res=await UserControllerService.getLoginUserUsingGet();
      console.log(res)
      if(res.code===0){
        commit("updateUser",res.data);
      }else{
        commit("updateUser",{
          ...state.loginUser,
          userRole: ACCESS_ENUM.NOT_LOGIN,
        });
      }
      
    },
  },
  // 变更函数
  mutations: {
    // 更新用户信息
    updateUser(state, payload) {
      state.loginUser = payload;
    },
  },
} as StoreOptions<any>;